<template>
	<view class="curriculum f18" ref="form">
		<uni-forms :rules="rules" :value="formData" validate-trigger="bind" err-show-type="undertext">
			<uni-group title="基本信息" top="0">
				<uni-forms-item name="userName" required label="姓名">
					<uni-easyinput type="text" disabled :inputBorder="true" v-model="wyuMsg.userName"
						placeholder="请输入用户名">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="institute" required label="学院">
					<uni-easyinput type="text" disabled :inputBorder="true" v-model="wyuMsg.institute"
						placeholder="请输入用户名">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="major" required label="专业">
					<uni-easyinput type="text" disabled :inputBorder="true" v-model="wyuMsg.major" placeholder="请输入用户名">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="connect" required label="联系方式">
					<uni-easyinput type="text" :disabled="isLoading" :inputBorder="true" v-model="formData.connect"
						placeholder="请输入联系方式">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="forte" required label="擅长">
					<uni-easyinput maxlength="80" :disabled="isLoading" type="textarea" :inputBorder="true"
						v-model="formData.forte" placeholder="请填写个人擅长(80字以内)">
					</uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="intention" required label="个人团队意向">
					<uni-easyinput maxlength="150" :disabled="isLoading" type="textarea" :inputBorder="true"
						v-model="formData.intention" placeholder="请填写个人团队意向(150字以内)">
					</uni-easyinput>
				</uni-forms-item>
			</uni-group>
			<view>
				<button :loading="isLoading" type="default" @click="submitForm">保存</button>
			</view>
		</uni-forms>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				isLoading: false,
				wyuMsg: {
					institute: '',
					major: '',
					userName: ''
				},
				formData: {
					connect: '',
					forte: '',
					intention: ''
				},
				rules: {
					name: {
						connect: [{
								required: true,
								errorMessage: '请输入手机号码'
							},
							{
								maxLength: 11,
								errorMessage: '手机号码为11位'
							}
						]
					},
					forte: {
						connect: [{
								required: true,
								errorMessage: '请填写个人擅长'
							},
							{
								maxLength: 80,
								errorMessage: '不超过80个字'
							}
						]
					},
					intention: {
						connect: [{
								required: true,
								errorMessage: '请填写个人团队意向'
							},
							{
								maxLength: 150,
								errorMessage: '不超过150个字'
							}
						]
					},
				}
			}
		},
		methods: {
			onKeyInput(type, e) {
				switch (type) {
					case 'connect':
						this.formData.connect = e.target.value
						break;
					case 'forte':
						this.formData.forte = e.target.value
						break;
					case 'intention':
						this.formData.intention = e.target.value
						break;
				}

			},
			getData() {

			},
			async submitForm() {
				if (this.isLoading) return
				if (this.formData.connect == '' || this.formData.connect.length == 0) {
					uni.showToast({
						title: '请填写联系方式',
						icon: 'error'
					})
					return
				}
				if (this.formData.forte == '' || this.formData.forte.length == 0) {
					uni.showToast({
						title: '请填写个人擅长',
						icon: 'error'
					})
					return
				}
				if (this.formData.intention == '' || this.formData.intention.length == 0) {
					uni.showToast({
						title: '请填写个人团队意向',
						icon: 'error'
					})
					return
				}
				const data = {
					...this.formData
				}
				console.log(data, 134);
				try {
					this.isLoading = true
					this.$nextTick(async () => {
						const result = await this.$mjcrequest.request({
							url: this.$api.saveResume,
							header: this.$aplsjsonheader,
							data: JSON.stringify(data),
							isToast: true
						})

						this.$setTimeoutback()
						this.isLoading = false
					})
				} catch (e) {
					console.log(e);
					this.isLoading = false
					this.$errMessageToast(e)
					//TODO handle the exception
				}
			},
		},
		async created() {
			console.log(this);
			try {
				const result = await this.$mjcrequest.request({
					url: this.$api.getresume,
					method: 'GET',
					header: {
						token: this.$token,
						"content-Type": "application/json",
					},


				})
				this.wyuMsg = {
					...this.wyuMsg,
					...result.wyuMsg
				};
				console.log(result);
				this.formData.connect = result.resumeMsg.connect
				this.formData.forte = result.resumeMsg.forte
				this.formData.intention = result.resumeMsg.intention
			} catch (e) {
				//TODO handle the exception
				this.$errMessageToast(e)
			}

		}
	}
</script>

<style scoped lang="less">
	.curriculum {
		background-color: #fff;
		height: 100vh;
		overflow: auto;
		padding-bottom: 20px;
	}

	.titleTip {
		padding: 10px 20px;
		background-color: #f9f9f9;
		position: relative;
		font-weight: 500;

		&::before {
			content: '';
			width: 8rpx;
			height: 18px;
			display: inline-block;
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			left: 10px;
			background-color: #bfbfbf;
		}
	}
</style>
